package com.lumlord.common.conf;

import java.util.List;

import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.google.common.base.Optional;
import com.lumlord.common.annotation.Api;


import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;
 
@Component
@Order(Ordered.HIGHEST_PRECEDENCE - 10)
public class ApiSwagger implements OperationBuilderPlugin {
 
    @Override
    public void apply(OperationContext context) {
        Optional<Api> api = context.findAnnotation(Api.class);
        if (api.isPresent() && StringUtils.hasText(api.get().actionName())) {
          context.operationBuilder().summary(api.get().actionName());
        }else {
        	context.operationBuilder().summary(66+"");
        }
         
    }
 
    @Override
    public boolean supports(DocumentationType delimiter) {
        return true;
    }
 
}
